//
//  TNAccountTableViewCell.m
//  TravelNotes
//
//  Created by 黄锋 on 15/8/13.
//  Copyright (c) 2015年 王浩宇. All rights reserved.
//

#import "TNAccountTableViewCell.h"
#import "Macro.h"
#import "UILabel+LJLabel.h"

@implementation TNAccountTableViewCell

- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        _consume = [[UILabel alloc] initWithFrame:CGRectMake(20, 20, 40, 20)];
        [self.contentView addSubview:_consume];
        _money = [[UILabel alloc] initWithFrame:CGRectMake(150, 20, SCREEN_WIDTH - 180, 20)];
        _money.font = [UIFont systemFontOfSize:12];
        _money.textAlignment = NSTextAlignmentRight;
        [self.contentView addSubview:_money];
        UIImageView *iv = [[UIImageView alloc] initWithFrame:CGRectMake(SCREEN_WIDTH - 20, 20, 10, 20)];
        iv.image = [UIImage imageNamed:@"ArrowRight"];
        [self.contentView addSubview:iv];
        _time = [[UILabel alloc] initWithFrame:CGRectMake(20, 50, SCREEN_WIDTH - 40, 20)];
        _time.numberOfLines = 0;
        _time.font = [UIFont systemFontOfSize:14];
        [self.contentView addSubview:_time];
        self.selectionStyle = UITableViewCellSelectionStyleNone;
    }
    return self;
}

- (void)setModel:(TNAccountModel *)model
{
    _model = model;
    _consume.text = model.consume;
    _money.text = [NSString stringWithFormat:@"%@%@", model.money, model.unit];
    NSString *string;
    if (model.detailed.length) {
        string = [NSString stringWithFormat:@"%@, %@", model.detailed, model.time];
    } else {
        string = model.time;
    }
    _time.text = string;
    CGRect newFrame = _time.frame;
    newFrame.size.height = [UILabel heightOfLabelByStr:_time.text fontSize:14 width:SCREEN_WIDTH - 40];
    _time.frame = newFrame;
}

+ (CGFloat)heightForCellOfModel:(TNAccountModel *)model
{
    static CGFloat height;
    if (!height) {
        NSString *string;
        if (model.detailed.length) {
            string = [NSString stringWithFormat:@"%@, %@", model.detailed, model.time];
        } else {
            string = model.time;
        }
        height = 60 + [UILabel heightOfLabelByStr:string fontSize:14 width:SCREEN_WIDTH - 40];
    }
    return height;
}

@end
